home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / TECHNICA / AUTOCAD / H107.ZIP / APR91.ZIP / PDIM.LSP < prev    next >
Text File  |  1991-05-13  |  7KB  |  293 lines

  1. ; PDIM.LSP   [Article Figure 1]   (c)1991, Phil Kreiker
  2.  
  3. ;--------------------------------------------------------------
  4. ; PDim.LSP -- COPYRIGHT 1990 BY LOOKING GLASS MICROPRODUCTS
  5. ;--------------------------------------------------------------
  6. (Setq
  7.    vplayer  "VPORTS"
  8.    dimlayer "DIMS"
  9.    ucs      1
  10. )
  11. ;--------------------------------------------------------------
  12. ; Load-time chewing gum
  13. (Princ "\n")
  14. (Setq bcount 0)
  15. (Defun bump ()
  16.    (Setq bcount (1+ bcount))
  17.    (Princ
  18.       (Strcat
  19.          "\rLoading PDim.Lsp v 1.0 ["
  20.          (Nth
  21.             (Rem bcount 4)
  22.             '("/" "-" "\\" "|")
  23.          )
  24.          "] Copyright 1990 by Looking Glass Microproducts"
  25.       )
  26.    )
  27. )
  28. ;-----------------------------------------------------
  29. ; Item from association list
  30. (bump)
  31. (Defun item (n e)
  32.    (CDR (Assoc n e))
  33. )
  34. ;-----------------------------------------------------
  35. ; Error Handler
  36. (bump)
  37. (Defun PDim-error (s)
  38.    (If (/= S "Function cancelled")
  39.       (Princ s)
  40.    )
  41.    (Command)
  42.    (Command)
  43.    (Command ".UNDO" "e")
  44.    (If undoit
  45.       (Progn (Command ".U"))
  46.    )
  47.    (moder)
  48. )
  49. ;-----------------------------------------------------
  50. ; System variable save
  51. (bump)
  52. (Defun modes (a)
  53.    (Setq MLST Nil)
  54.    (Repeat
  55.       (Length a)
  56.       (Setq
  57.          MLST (Append
  58.                  MLST
  59.                  (List
  60.                     (List
  61.                        (CAR a)
  62.                        (GetVar (CAR a))
  63.                     )
  64.                  )
  65.               )
  66.       )
  67.       (Setq a (CDR a))
  68.    )
  69. )
  70. ;-----------------------------------------------------
  71. ; System variable restore
  72. (bump)
  73. (Defun moder ()
  74.    (Repeat
  75.       (Length MLST)
  76.       (Setvar
  77.          (CAAR MLST) (CADAR MLST)
  78.       )
  79.       (Setq MLST (CDR MLST))
  80.    )
  81.    (Setq *Error* olderror)
  82.    (Princ)
  83. )
  84. ;-----------------------------------------------------
  85. ; Get a Viewport
  86. (bump)
  87. (Defun getvport (/ again ename ent esel)
  88.    (Setq again T)
  89.    (While again
  90.       (If (Setq
  91.              ename (CAR
  92.                       (Setq
  93.                          esel (EntSel "\nSelect viewport: ")
  94.                       )
  95.                    )
  96.           )
  97.          (Progn
  98.             (Setq ent (EntGet ename))
  99.             (If (= (item 0 ent) "VIEWPORT")
  100.                (Progn (Setq again Nil) esel)
  101.                (Princ "\nNot a viewport.")
  102.             )
  103.          )
  104.       )
  105.    )
  106. )
  107. ;-----------------------------------------------------
  108. ; Highlight Viewport Entity
  109. (Defun highlight (vpent color hlite / vpcen half-height half-width
  110.                   p1 p2 p3 p4)
  111.    (Setq
  112.       vpcen       (item 10 vpent)
  113.       half-height (* 0.5 (item 41 vpent))
  114.       half-width  (* 0.5 (item 40 vpent))
  115.       p1          (Trans
  116.                      (MapCar
  117.                         '+
  118.                         vpcen
  119.                         (List
  120.                            (- half-width)
  121.                            (- half-height)
  122.                            0.0
  123.                         )
  124.                      )
  125.                      vpname
  126.                      ucs
  127.                   )
  128.       p2          (Trans
  129.                      (MapCar
  130.                         '+
  131.                         vpcen
  132.                         (List
  133.                            (- half-width)
  134.                            (+ half-height)
  135.                            0.0
  136.                         )
  137.                      )
  138.                      vpname
  139.                      ucs
  140.                   )
  141.       p3          (Trans
  142.                      (MapCar
  143.                         '+
  144.                         vpcen
  145.                         (List
  146.                            (+ half-width)
  147.                            (+ half-height)
  148.                            0.0
  149.                         )
  150.                      )
  151.                      vpname
  152.                      ucs
  153.                   )
  154.       p4          (Trans
  155.                      (MapCar
  156.                         '+
  157.                         vpcen
  158.                         (List
  159.                            (+ half-width)
  160.                            (- half-height)
  161.                            0.0
  162.                         )
  163.                      )
  164.                      vpname
  165.                      ucs
  166.                   )
  167.    )
  168.    (Command
  169.       "layer" "off" vplayer ""
  170.    )
  171.    (GrDraw p1 p2 color hlite)
  172.    (GrDraw p2 p3 color hlite)
  173.    (GrDraw p3 p4 color hlite)
  174.    (GrDraw p4 p1 color hlite)
  175. )
  176. ;-----------------------------------------------------
  177. ; PDim MAIN ROUTINE
  178. (bump)
  179. (Defun PDim (/ ok vpnum vpname vpent vport vpnum)
  180.    (If (Not
  181.           (Setq
  182.              ok (Zerop (GetVar "tilemode"))
  183.           )
  184.        )
  185.       (Prompt
  186.          "\n** Command not allowed unless TILEMODE is set to 0 **"
  187.       )
  188.    )
  189.    (Setq undoit T)
  190.    (If ok
  191.       (Progn
  192.          (If (Not
  193.                 (Setq
  194.                    in_pspace (= 1 (CAAR (Vports)))
  195.                 )
  196.              )
  197.             (Progn
  198.                (Command ".pspace")
  199.                (Prompt
  200.                   "\nSwitching to Paper Space."
  201.                )
  202.             )
  203.          )
  204.          (If (Not
  205.                 (Setq
  206.                    ok (TblSearch "layer" vplayer)
  207.                 )
  208.              )
  209.             (Prompt
  210.                (Strcat
  211.                   "\n** Viewport layer '"
  212.                   vplayer
  213.                   "' does not exist. **"
  214.                )
  215.             )
  216.          )
  217.       )
  218.    )
  219.    (If ok
  220.       (If (Not
  221.              (Setq
  222.                 ok (TblSearch "layer" dimlayer)
  223.              )
  224.           )
  225.          (Prompt
  226.             (Strcat
  227.                "\n** Dimension layer '"
  228.                dimlayer
  229.                "' does not exist. **"
  230.             )
  231.          )
  232.       )
  233.    )
  234.    (If ok
  235.       (Progn
  236.          (Command
  237.             ".layer" "t" vplayer "t" dimlayer "on" vplayer "on"
  238.             dimlayer "set" dimlayer ""
  239.          )
  240.          (Setq
  241.             vport (getvport)
  242.             ok    vport
  243.          )
  244.       )
  245.    )
  246.    (If ok
  247.       (Progn
  248.          (Setq
  249.             vpnum (item
  250.                      69
  251.                      (Setq
  252.                         vpent (EntGet
  253.                                  (Setq vpname (CAR vport))
  254.                               )
  255.                      )
  256.                   )
  257.          )
  258.          (Command ".mspace")
  259.          (Setvar "cvport" vpnum)
  260.          (Command ".ucs" "v")
  261.          (Command ".pspace")
  262.          (Command
  263.             "dim" "dimlfac" "v" vport "exit"
  264.          )
  265.          (Setvar "dimzin" 8) ; suppress trailing zeros
  266.          (Prompt
  267.             (Strcat
  268.                "\nNew value for DIMLFAC: "
  269.                (RtoS (GetVar "dimlfac") 2 4)
  270.             )
  271.          )
  272.          (highlight vpent -1 1)
  273.       )
  274.    )
  275. )
  276. ;-----------------------------------------------------
  277. ; PDim COMMAND
  278. (bump)
  279. (Defun c:PDim (/ olderror undoit)
  280.    (modes '("cmdecho" "dimzin"))
  281.    (Setq
  282.       olderror *Error*
  283.       *Error*  PDim-error
  284.    )
  285.    (Setvar "cmdecho" 0)
  286.    (Command ".undo" "group")
  287.    (PDim)
  288.    (Command ".undo" "e")
  289.    (moder)
  290. )
  291. (c:PDim)
  292. 
  293.